package com.clstu.api;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class API_ {
    public static void main(String[] args) throws UnknownHostException {
        //1.获取本机的InetAddress对象
        InetAddress localHost = InetAddress.getLocalHost();//获取本机型号和IP地址
        System.out.println(localHost);

        //根据名称获取本机的InetAddress对象
        InetAddress host1 = InetAddress.getByName("DESKTOP-79641T2");
        System.out.println(host1);

        //根据域名返回InetAddress对象，比如 www.baidu.com(www.taobao.com用的是ipv6)
        InetAddress host2 = InetAddress.getByName("www.baidu.com");
        System.out.println(host2);

        //通过InetAddress 对象， 返回ip地址
        System.out.println("host2 的IP地址===="+host2.getHostAddress());

        //通过InetAddress 对象 ， 返回域名
        System.out.println("host2 的域名======"+host2.getHostName());

    }
}
